audiowriter module#11106
Conversation
dhalbert
left a comment
There was a problem hiding this comment.
If this is only going to be files, maybe call it audiofilewriter? If not, are there other possible similar classes inside the module?
We also talked about having a more generalized audio sink: just a buffer or two that you could examine do what you want to with it. It would need to be pollable so you could tell when it was ready to examine. Perhaps that could be a "tee", so you could pass the audio on after changing it (assuming the code can keep up). Or it could just be a dead-end. (Is there a use for a /dev/null audio sink??)
|
There are a few other sinks and other objects that would be cool I think, but in my mind they could live in their own modules instead of this one. A I do still think a more generalized buffer could be useful as well. Though I imagine it sitting within a chain instead of as a sink at the end of it. I think it could be used for audio reactive neopixels without a microphone. Audio generated by synthio and/or effects chains could pass thru a link in the chain that exposes the current data which could be analyzed with FFT and output to neopixels. The audio itself would continue through the chain to the sink that outputs it to wherever. I think a splitter object is another that could be useful. Maybe the generalized buffer could be used for this. Right now it doesn't seem possible to take the same raw sample, pass it thru multiple different effects chains independently and then merge the results back together with Maybe one or both of the latter two could be done with the get_buffer() function that gets exposed by the AUIDIO_DEBUG build flag. I tried using that function to record to a file before implementing |
# Conflicts: # locale/circuitpython.pot
|
This is renamed to |
| //| :param int buffer_size: Size in bytes of the internal RAM ring that | ||
| //| decouples file-write latency from the source. Larger values tolerate | ||
| //| longer write stalls (e.g. a slow SD card) at the cost of RAM. |
There was a problem hiding this comment.
The code makes this a minimum of 512, but that's not documented. Maybe worth documenting. Also should it be a multiple of 512 or is any size >= 512 ok?
This new module provides an audio sink that writes to a file. Its API is essentially a drop in replacement in code for where you would normally use
AudioOutor one of the variations of it.This allows saving audio generated from synthio and/or effects chains.
All of my testing has been on Metro RP2350. There are perhaps more ports or devices that this could be enabled on, right now I kept it only to rpi port and esp32s2. I left out the rest of the esp devices because they had
audioiodisabled, but maybe it would make more sense to have this depend on synthio and/or the audio effects flag since this writer functionality could be used with those even on ports that do not have other options for audio out theoretically.